<%@ page import="utils.StringUtils" %>
<%@ page import="database.UserDb" %><%--
  Created by IntelliJ IDEA.
  User: Thinkpad
  Date: 2016/12/11
  Time: 16:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>导入学生中</title>
</head>
<body>
<%
    String id = StringUtils.getUtf8String(request.getParameter("id"));
    String name = StringUtils.getUtf8String(request.getParameter("name"));
    String sex = StringUtils.getUtf8String(request.getParameter("sex"));
    String institute = StringUtils.getUtf8String(request.getParameter("institute"));
    String dormitory = StringUtils.getUtf8String(request.getParameter("dormitory"));
    String tel = StringUtils.getUtf8String(request.getParameter("tel"));
    String branch = StringUtils.getUtf8String(request.getParameter("branch"));
    String grade = StringUtils.getUtf8String(request.getParameter("grade"));
    String email = StringUtils.getUtf8String(request.getParameter("email"));
    String stuClass = StringUtils.getUtf8String(request.getParameter("stuClass"));
    if (StringUtils.isEmpty(id) || StringUtils.isEmpty(name)) {
        response.getWriter().print("<script>alert('学号和姓名是必填项！');history.go(-1);</script>");
    } else {
        if (UserDb.userNotExists(id)) {
            UserDb.insertStudent(id, name, sex, institute, dormitory, tel, branch, grade, email, "");
            UserDb.insertStudentClass(id, stuClass);
//            System.out.println("1");
            response.getWriter().print("<script>alert('导入成功！'); location.href='../importStudent.jsp';</script>");
        } else {
            UserDb.insertStudent(id, name, sex, institute, dormitory, tel, branch, grade, email, "");
            UserDb.insertStudentClass(id, stuClass);
//            System.out.println("2");
            response.getWriter().print("<script>alert('该学号已存在，学生信息已更新。导入成功！'); location.href='../importStudent.jsp';</script>");
        }
    }
%>
</body>
</html>
